/*
 *	Copyright (C) 2008 - Mauricio Bieze Stefani
 *	This file is part of the Insano Game Engine.
 *
 *	Insano is free software: you can redistribute it and/or modify
 *	it under the terms of the GNU General Public License as published by
 *	the Free Software Foundation, either version 3 of the License, or
 *	(at your option) any later version.
 *
 *	Insano is distributed in the hope that it will be useful,
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *	GNU General Public License for more details.
 *
 *	You should have received a copy of the GNU General Public License
 *	along with Insano.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef CAMERA_H
#define CAMERA_H

#include <irrlicht.h>

class Camera
{
	public:
		irr::scene::ICameraSceneNode *node;

		float distance;
		float pitch; //TODO: convert to RAD to optimize
		float yaw;   //TODO: convert to RAD to optimize

		Camera(irr::scene::ISceneManager *mng) : smgr(mng), parent(NULL), selector(NULL)
		{
			reset();
			node = smgr->addCameraSceneNode();
		}

		virtual ~Camera()
			{}

		void reset()
		{
			distance=20;
			pitch=30;
			yaw=90;
		}

		float sumDistance(float dist)
		{
			distance += dist;
			if(distance<10)
				distance=10;
			else if(distance>80)
				distance=80;
			return distance;
		}

		float sumPitch(float p)
		{
			pitch+=p;
			if (pitch>85)
				pitch=85;
			else if (pitch<-85)
				pitch=-85;
			return pitch;
		}

		float sumYaw(float y)
		{
			yaw+=y;
			if(yaw>360)
				yaw-=360;
			else if(yaw<-360)
				yaw+=360;
			return yaw;
		}

		void setParent(irr::scene::ISceneNode *paren)
			{ parent=paren; }
		void setWorld(irr::scene::ITriangleSelector *select)
			{ selector=select; }
		void setTranslate(const irr::core::vector3df& trans)
			{ translate = trans; }

		int updatePosition();

	private:
		irr::scene::ISceneManager *smgr;
		irr::scene::ISceneNode *parent;
		irr::scene::ITriangleSelector *selector;
		irr::core::vector3df translate;
};

#endif // CAMERA_H
